package model;

import com.example.menhoo.toollibrary.common.assist.Check;

import fragment.APP;
import fragment.Contacts1;
import fragment.IM2;
import fragment.MY;
import fragment.NewsListFragment;
import fragment.WebHtml;

/**
 * Created by yanglei on 15/9/18.
 */
public class TabModel extends DbModel{

    public String code;
    public String name;
    public int icon;
    public int icon_sel;
    public String iconUrl;
    public String htmlUrl;
    public String type="html";
    public boolean isShow=true;
    public String permisson;
    public String size="0M";
    public String version="1.0.0.1";
    public String desc="应用";

    @Override
    public String toString() {
        return "TabModel{" +
                "code='" + code + '\'' +
                ", name='" + name + '\'' +
                ", icon=" + icon +
                ", icon_sel=" + icon_sel +
                ", iconUrl='" + iconUrl + '\'' +
                ", htmlUrl='" + htmlUrl + '\'' +
                ", type='" + type + '\'' +
                ", isShow=" + isShow +
                ", permisson='" + permisson + '\'' +
                ", size='" + size + '\'' +
                ", version='" + version + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }

    /**
     * 权限
     * @return
     */
    public String[] getPermissons(){
        if(Check.isEmpty(this.permisson)){
            return null;
        }
        return this.permisson.split("/");
    }

    public Class getFragment(){
        if(Check.isEmpty(code)){
            return null;
        }
        Class fragment;
        if (code.equalsIgnoreCase("IM") || name.equalsIgnoreCase("对话")) {
            fragment = IM2.class;
        } else if (code.equalsIgnoreCase("People") || name.equalsIgnoreCase("联系人")) {
            fragment = Contacts1.class;
        } else if (code.equalsIgnoreCase("My") || name.equalsIgnoreCase("我")) {
            fragment = MY.class;
        } else if (code.equalsIgnoreCase("Apps") || name.equalsIgnoreCase("应用")) {
            fragment = APP.class;
        } else if(type.equals("news")){
            fragment = NewsListFragment.class;
        }else{
            fragment = WebHtml.class;
        }
        return fragment;
    }
}
